package com.zhengsr.latte.utils;

import com.zhengsr.latte.app.Latte;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by zhengshaorui on 2018/5/22.
 */

public class MyFileUtil {

    /**
     * 读取assets目录下的文件,并返回字符串
     */
    public static String getJsonFromAssets( String fileName) {
        BufferedReader reader = null;
        StringBuilder sbBuilder = null;
        try {
            reader = new BufferedReader(new InputStreamReader(Latte.getApplication().getAssets().open(fileName),
                    "utf-8"));
            String jsonString;
            sbBuilder = new StringBuilder();
            while ((jsonString = reader.readLine()) != null) {
                sbBuilder.append(jsonString);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sbBuilder.toString();
    }
}
